﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using HZ.Supervise.Model.Enum;
using HZ.Supervise.Model;
using System.Data;
using HZ.Supervise.IBLL;

namespace HZ.Supervise.Web.Secondphase.NewReport
{
    public partial class Warnwords : BasePage
    {
        HZ.Supervise.IBLL.IExecuteContext ih = HZ.Supervise.BLLFactory.ExecuteContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ddlArea.InitAreaID = CurrentAccount.GetUser().Org.Area.AreaID;
                //SetBind();
            }
        }
        protected void SetBind()
        {
            string s = "and SubStatus=1";
            if (!string.IsNullOrEmpty(txtYear.Text.Trim()))
            {
                s += string.Format(" and CountYear='{0}'", txtYear.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtMonth.Text.Trim()))
            {
                s += string.Format(" and CountMonth='{0}'", txtMonth.Text.Trim());
            }
            if (ddlArea.SelectedAreaID == "510000")
            {
                s += "and areaid like '51%'";
            }
            else
            {
                s += "and areaid like '" + ddlArea.SelectedAreaID + "%'";
            }
            int totalrecord = 0;
            gvw.DataSource = ih.GetWarnwords(s, this.AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalrecord);
            gvw.DataBind();
            AspNetPager1.RecordCount = totalrecord;
        }
        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            SetBind();
        }
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
        }
        protected void gvw_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Sub")//产品提交
            {
                string id = e.CommandArgument.ToString();
                if (ih.WarnwordsSubmit(id, 1) > 0)
                {
                    HZ.Web.WebUtil.Alert("提交成功!", this.Page);
                }
                else
                {
                    HZ.Web.WebUtil.Alert("提交失败!", this.Page);
                }

                SetBind();
            }

        }

        //protected void gvwProduceCatalog_RowUpdating(object sender, GridViewUpdateEventArgs e)
        //{
        
        //        string id = e.CommandArgument.ToString();
        //        //跳转
        //        Response.Redirect("UploadZip.aspx?UrlID==+id");

        //}

        protected void gvw_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                LinkButton lb = e.Row.FindControl("lbSub") as LinkButton;
                LinkButton lbUP = e.Row.FindControl("lbUpdate") as LinkButton;
                string IsSub = gvw.DataKeys[e.Row.RowIndex]["SubStatus"].ToString();
                  string ISup = gvw.DataKeys[e.Row.RowIndex]["IsUp"].ToString();
                //string IsNew = gvwProduceCatalog.DataKeys[e.Row.RowIndex]["IsNew"].ToString();
                  //if (IsSub == "1")
                  //{
                  //    lbUP.Text = "上传";
                  //    lbUP.Enabled = false;
                  //}
                  //else
                  //{
                  //    lbUP.Text = "上传";
                  //}


                if (IsSub == "1")
                {
                    lb.Text = "已提交";
                    lb.Enabled = false;
                }
                else if (IsSub == "0" && ISup == "查看")
                {
                    lb.Text = "提交";
                }
                else
                {
                    lb.Text = "提交";
                    lb.Enabled = false;
                }

            }
        }
    }

}
